package com.sskj.gcc.presenter;

import com.lzy.okgo.OkGo;
import com.lzy.okgo.model.Response;
import com.sskj.common.base.HttpData;
import com.sskj.common.util.MD5Util;
import com.sskj.common.util.ToastUtil;
import com.sskj.gcc.ui.activity.WithdrawActivity;
import com.sskj.gocoin.MyAppLication;
import com.sskj.gocoin.common.Constants;
import com.sskj.gocoin.m.HttpConfig;
import com.sskj.gocoin.m.bean.ChargeCoinItemBean;
import com.sskj.gocoin.m.bean.CoinFeeBean;
import com.sskj.gocoin.p.base.BasePresenter;
import com.sskj.gocoin.utils.SPUtils;
import com.sskj.lib.http.JsonCallBack;

import java.util.List;

public class WithdrawActivityPresenter extends BasePresenter<WithdrawActivity> {

    public void withdraw(String num, String tpwd, String code, String qianbao_url, int assetId,String google_code) {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.WITHDRAW)
                .params("money", num)
                .params("payment_password", MD5Util.getMd5Value(tpwd))
                .params("code", code)
                .params("google_code", google_code)
                .params("address", qianbao_url)
                .params("pid", assetId)
                .execute(new com.sskj.lib.http.JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        ToastUtil.showShort(httpListData.getMsg());
                        if (httpListData.getCode() == 200) {
                            mView.updateUI();
                        }
                    }
                });
    }

    public void sendCode() {
        String phone = (String) SPUtils.get(MyAppLication.getApplication(), Constants.SP_MOBILE, "");
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SMS_SEND)
                .params("mobile", phone)
                .params("type", 5)
                .execute(new com.sskj.lib.http.JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.startCount();
                        }
                        ToastUtil.showShort(httpListData.getMsg());
                    }
                });
    }

    public void sendEmail() {
        OkGo.<HttpData>post(HttpConfig.BASE_URL + HttpConfig.SEND_EMAIL)
                .params("email", MyAppLication.getMobile())
                .params("is_app", "1")
                .execute(new JsonCallBack<HttpData>() {
                    @Override
                    public void onSuccess(Response<HttpData> response) {
                        HttpData httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.startCount();
                        }
                        ToastUtil.showShort(httpListData.getMsg());
                    }
                });
    }

    public void requestUserAssetList() {
        OkGo.<HttpData<List<ChargeCoinItemBean>>>get(HttpConfig.BASE_URL + HttpConfig.ASEET_LIST)
                .execute(new JsonCallBack<HttpData<List<ChargeCoinItemBean>>>() {
                    @Override
                    public void onSuccess(Response<HttpData<List<ChargeCoinItemBean>>> response) {
                        HttpData<List<ChargeCoinItemBean>> httpListData = response.body();
                        if (httpListData.getCode() == 200) {
                            mView.onDataSuccess(httpListData.getData());
                        }
                    }
                });
    }


    //验证谷歌验证码
    public void requestGoogleCheck(String googleCode) {

        mView.googleCheckSuccess(googleCode);

//        OkGo.<HttpData<String>>post(HttpConfig.BASE_URL + HttpConfig.GOOGLE_LOGIN)
//                .params("dyGoodleCommand", googleCode)
//                .execute(new JsonCallBack<HttpData<String>>() {
//                    @Override
//                    public void onSuccess(Response<HttpData<String>> response) {
//                        HttpData<String> body = response.body();
//                        if (body.getCode() == 200) {
//                            mView.googleCheckSuccess();
//                        } else {
//                            com.sskj.gocoin.utils.ToastUtil.showShort(body.msg);
//                        }
//                    }
//                });
    }


}
